package com.boot3.controller;

import com.boot3.pojo.Result;
import com.boot3.pojo.User;
import com.boot3.service.UserService;
import com.boot3.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wzm
 * @create 2023-11-30 10:27
 * project_name:web2310
 * @Description
 */
@RestController  //@Controller+@ResponseBody
public class UserController {
    //创建Servcie对象
    //@Autowired //注入
    //@Qualifier("userServiceImpl") //指定要注入的Bean的对象名

    @Resource(name = "userServiceImpl02")  //指定注入的ioc容器中的bean名字
    private UserService userService;

    /*@Autowired翻译为自动装配
    * 默认是按照变量的类型去ioc中招某个类型的对象 然后进行注入*/

    /**
     * 根据id查询用户信息
     * @param id 用户id
     * @return 统计结果类将数据作为data属性传入
     */
    @RequestMapping("/getUserById/{id}")
    public Result getUserById(@PathVariable Integer id){
        //接收请求的参数
       //调用service完成功能
      User user =  userService.getUserById(id);

        //判断并返回数据
        return Result.success(user);
    }
}
